package com.igeek.clud_system.controller;

import com.igeek.clud_system.entity.ClubMembers;
import com.igeek.clud_system.entity.ClubMembershipRequests;
import com.igeek.clud_system.pojo.Goby;
import com.igeek.clud_system.pojo.ResponseResult;
import com.igeek.clud_system.service.ClubRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ClubRequestController {

    @Autowired
    ClubRequestService clubRequestService;

    /**
     * 用于判断用户是否为该社团成员
     */
    @GetMapping("clubMembers/{clubId}/{studentId}")
    public ResponseResult getClubStudent(@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        ResponseResult result = new ResponseResult();
        System.out.println(studentId+" "+clubId);
        List<ClubMembers> members = clubRequestService.findMembers(clubId, studentId);
        if(members.size() > 0){
            result.setState(400);
        }else {
            result.setState(200);
        }
        return result;
    }

    /**
     * 同于判断用户是否已经发送加入申请
     */
    @GetMapping("request/{studentId}/{clubId}")
    public ResponseResult getRequest(@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        ResponseResult result = new ResponseResult();
        ClubMembershipRequests request = clubRequestService.findRequest(studentId, clubId);
        if(request != null){
            result.setState(400);
        }else {
            result.setState(200);
        }
        return result;
    }


    /**
     * 添加申请记录
     */
    @RequestMapping("insert/{studentId}/{clubId}")
    public ResponseResult insertRequest(@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        ResponseResult result = new ResponseResult();
        clubRequestService.insertRequest(studentId,clubId);
        return result;
    }

    /**
     * 同于判断用户是否已经发送退出出申请
     */
    @GetMapping("requestRe/{studentId}/{clubId}")
    public ResponseResult getRequestRe(@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        ResponseResult result = new ResponseResult();
        ClubMembershipRequests request = clubRequestService.findRequest2(studentId, clubId);
        if(request != null){
            result.setState(400);
        }else {
            result.setState(200);
        }
        return result;
    }

    /**
     * 添加退出申请记录
     */
    @RequestMapping("remove/{studentId}/{clubId}")
    public ResponseResult insertReRequest(@PathVariable("studentId")Integer studentId, @PathVariable("clubId")Integer clubId){
        ResponseResult result = new ResponseResult();
        clubRequestService.insertRequest2(studentId,clubId);
        return result;
    }

    /**
     * 获得所有社团的所有申请
     */
    @GetMapping("requestAll/{clubId}")
    public List<Goby> getAllRe(@PathVariable("clubId")Integer clubId){
        List<Goby> allRe = clubRequestService.getAllRe(clubId);
        return allRe;
    }

}
